package fr.sedoo.sssdata.server.sos;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.CharEncoding;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;

public class XmlBeansUtils {

	public static String toString(XmlObject object)
	{
		return object.xmlText(getXmlOptions());
	}
	
	private static XmlOptions getXmlOptions()
	{
		XmlOptions options = new XmlOptions();
		options.setUseDefaultNamespace();
		options.setCharacterEncoding(CharEncoding.UTF_8);
		options.setSavePrettyPrint();
		options.setSavePrettyPrintIndent(4);
		options.setSaveNamespacesFirst();
		options.setSaveAggressiveNamespaces();
		Map suggestedPrefixes = new HashMap();
		suggestedPrefixes.put(SensorMLConstants.SENSORML_NAMESPACE,SensorMLConstants.SENSORML_PREFIX);
		suggestedPrefixes.put(SosRestConstants.SOSREST_NAMESPACE,SosRestConstants.SOSREST_PREFIX);
		suggestedPrefixes.put("http://www.opengis.net/om/2.0","om");
		suggestedPrefixes.put("http://www.opengis.net/sos/2.0","sos");
		suggestedPrefixes.put("http://www.opengis.net/gml/3.2","gml");
		suggestedPrefixes.put("http://www.w3.org/1999/xlink","xlink");
		suggestedPrefixes.put("http://www.opengis.net/swe/2.0","swe");
		suggestedPrefixes.put("http://www.opengis.net/swe/1.0.1","swe101");
		
		
		options.setSaveSuggestedPrefixes(suggestedPrefixes);
		return options;
	}
	
}
